// Copyright (c) Microsoft Corporation.  All rights reserved.
#pragma once

#define COUNTOF(a)  (sizeof(a)/sizeof(a[0]))

#define SAFE_DELETE(p)  do{\
        if (p) {\
            delete p;\
            p = NULL;\
        }\
    }while(0)

#define SAFE_RELEASE(pi)    do{\
        if (pi) {\
            pi->Release();\
            pi = NULL;\
        }\
    }while(0)

#define SAFE_FREE(p)    do{\
        if (p) {\
            free((PVOID)p);\
            p = NULL;\
        }\
    }while(0)


//
// Convert UTF-8 String to UTF-16 String
// Caller must delete [] *ppszWideChar
//
HRESULT UTF8ToWideChar(
    __in_bcount(cbUTF8) const BYTE *pUTF8,
    __in DWORD cbUTF8,
    __deref_out_ecount(*pcchWideChar) LPWSTR *ppszWideChar,
    __out DWORD *pcchWideChar);

//
// Get SID Name
// Caller should do delete [] for returned names.
//
HRESULT GetAccountSidName(
    __in PSID pSid,
    __deref_out LPWSTR *ppwszUserName,
    __deref_out LPWSTR *ppwszDomainName);

